package cn.summit.sort;

import java.util.Arrays;

/**
 * 冒泡排序
 *
 * @author summit
 * @since 2021/8/15 21:40
 */
public class BubbleSortTest {


	public static void main(String[] args) {
		int[] arr = { 10, 6, 2, 1, 2, 3 };
		bubbleSort(arr);

		System.out.println(Arrays.toString(arr));
	}

	private static int[] bubbleSort(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					swap(arr, i, j);
				}
			}
		}

		return arr;
	}

	public static void swap(int[] arr, int a, int b) {
		int tmp = arr[a];
		arr[a] = arr[b];
		arr[b] = tmp;
	}

}
